package com.rao.crm.web.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.rao.crm.domain.User;
import org.apache.struts2.ServletActionContext;

/**
 * @author Srao
 * @version 1.0
 * @className PrivilegeInterceptor
 * @date 2019/9/22 21:31
 * @package com.rao.crm.web.interceptor
 * @description
 */
public class PrivilegeInterceptor extends MethodFilterInterceptor {
    @Override
    protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
        User existUser = (User) ServletActionContext.getRequest().getSession().getAttribute("existUser");
        if (existUser == null){
            ActionSupport actionSupport = (ActionSupport) actionInvocation.getAction();
            actionSupport.addActionError("您还没有登陆，没有权限查看");
            return actionSupport.LOGIN;
        }else {
            return actionInvocation.invoke();
        }
    }
}
